package com.erpanderp.wam.ac.view.project;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.AjaxBehaviorEvent;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.swing.SwingWorker;

import org.primefaces.component.menuitem.MenuItem;
import org.primefaces.component.selectonemenu.SelectOneMenu;
import org.primefaces.context.RequestContext;
import com.erpanderp.wam.ac.model.entity.project.ProjectAssignment;
import com.erpanderp.wam.ac.model.entity.project.ProjectAssignmentDetail;
import com.erpanderp.wam.ac.model.service.project.ProjectAssignmentDAO;
import com.erpanderp.wam.ac.model.service.project.ProjectAssignmentDetailDAO;
import com.erpanderp.wam.tm.model.service.RRFDAO;
import com.erpanderp.wam.usm.model.entity.projectandassignment.EmployeeProject;
import com.erpanderp.wam.usm.model.entity.projectandassignment.Project;
import com.erpanderp.wam.usm.model.entity.user.Employee;
import com.erpanderp.wam.usm.model.entity.user.EmployeeAndReporting;
import com.erpanderp.wam.usm.model.entity.user.WAMUser;
import com.erpanderp.wam.usm.model.service.projectandassignment.EmployeeProjectDAO;
import com.erpanderp.wam.usm.model.service.projectandassignment.ProjectDAO;
import com.erpanderp.wam.usm.model.service.user.EmployeeAndReportingDAO;
import com.erpanderp.wam.util.CommonLookup;
import com.erpanderp.wam.util.EmailUtil;
import com.erpanderp.wam.util.ValidationUtil;
import com.erpanderp.wam.util.WAMHostManager;
@ManagedBean
@ViewScoped
public class DomesticProjectAssignmentFormBean implements Serializable {

	private static final long serialVersionUID = 1L;
	HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
	HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
	ServletContext context = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
	
	
	private String selectedButton = CommonLookup.CREATE_PA_BUTTON;
	private boolean createDomesticProjectAssignmentForm;
	private boolean DomesticProjectAssignmentsList;
	
	///Create Domestic Project Assignment
	
	//ProjectDAO projectDAO = new ProjectDAO();
	//ProjectAssignmentDAO projectAssignmentDAO = new ProjectAssignmentDAO();
	RRFDAO rrfDAO = new RRFDAO();
	EmployeeAndReportingDAO employeeAndReportingDAO = new EmployeeAndReportingDAO();
	EmployeeProjectDAO employeeProjectDAO = new EmployeeProjectDAO();
	
	
	//private boolean FORM_VALID;
	
	//private ProjectAssignment projectAssignment = new ProjectAssignment();
	//private ProjectAssignmentDetail projectAssignmentDetail = new ProjectAssignmentDetail();
	//private Employee employee = new Employee();
	private EmployeeAndReporting employeeAndReporting = new EmployeeAndReporting();
	
	private EmployeeProject  employeeProject = new EmployeeProject();
	
	
	//private List<Project> projects = new ArrayList<Project>();
	//private Map<String, Long> projectsMap = new HashMap<String, Long>();
	
	//private Long selectedProjectId;
	//private Project selectedProject= new Project();
	
	//private WAMUser wamUser = new WAMUser();
	//private String projectAssignmentCode;
	//private String employeeId;
	//	private String contactNumber="";
	//	private String approvedBy="";
	//	private Float advanceAmount;
	//	private Float roomRentAdvance;
	//	private Date createDate;
	//	private String additionals;
	String EMAIL_MESSAGE;
	
	//private Employee reportingManager = new Employee();
	private Long reportingManagerId;
	private EmailUtil emailUtil = new EmailUtil();


	///Domestic Project Assignment List
	ProjectDAO projectDAO = new ProjectDAO();
	ProjectAssignmentDAO projectAssignmentDAO = new ProjectAssignmentDAO();
	ProjectAssignmentDetailDAO projectAssignmentDetailDAO = new ProjectAssignmentDetailDAO();
	
	private ProjectAssignment projectAssignment = new ProjectAssignment();
	private ProjectAssignmentDetail projectAssignmentDetail = new ProjectAssignmentDetail();
	private Employee employee = new Employee();
	private Project selectedProject= new Project();
	private WAMUser wamUser = (WAMUser) session.getAttribute(CommonLookup.SESSION_ATTRIBUTE_WAMUSER);
	private Employee reportingManager;
	
	private boolean SHOW_EDIT_DIALOG=false;
	private boolean FORM_VALID;
	private boolean renderApproveReject;
	private boolean renderUpdate;
	private boolean renderDisableUpdate;
	private boolean renderClose;
	private boolean renderProjectsAssignmentsList;
	

	private boolean renderProjectsAssignments;
	
	private List<ProjectAssignment> projectAssignmentsList = new ArrayList<ProjectAssignment>();
	private List<ProjectAssignmentDetail> projectAssignmentDetailList = new ArrayList<ProjectAssignmentDetail>();
	private List<EmployeeProject> employeeProjects = new ArrayList<EmployeeProject>();

    Map<String, Long> projectsMap = new HashMap<String, Long>();
	
	private Long projectAssignmentId;
	private Long selectedProjectId;
	
	private String projectAssignmentCode;
	private String employeeId;
	private String contactNumber="";
	private String approvedBy="";
	private Float advanceAmount;
	private Float roomRentAdvance;
	private Date createDate;
	private String additionals;
	
	
	
	
	public DomesticProjectAssignmentFormBean(){
		System.out.println("constructor start.................");
		System.out.println("projectAssignment.getEmergencycontactNumber()....................."+projectAssignment.getEmergencycontactNumber());
		
		///Create Domestic Project Assignment 
		  System.out.println(selectedProjectId);
		  setWamUser((WAMUser) session.getAttribute(CommonLookup.SESSION_ATTRIBUTE_WAMUSER));
		  projectAssignmentCode=CommonLookup.getAutoGeneratedDomesticProjectAssignmentCode(wamUser.getEmployee().getEmployeeCode());
		  System.out.println("projectAssignmentId.........."+projectAssignmentCode);
		  setCreateDate(new Date());
		  employee.setFirstName(wamUser.getEmployee().getFirstName());
		  employee.setLastName(wamUser.getEmployee().getLastName());
		  setEmployeeId(wamUser.getEmployee().getEmployeeCode());
		  setContactNumber(wamUser.getEmployee().getTelephone());
		  setApprovedBy(CommonLookup.PROJECTASSIGNMENT_DOMESTIC_INTERNATIONAL_APPROVER);
		  //reportingManager = rrfDAO.getReportingManager(wamUser.getEmployee().getEmployeeId());
		  employeeAndReporting = employeeAndReportingDAO.getEmployeeReportingDetail(wamUser.getEmployee().getEmployeeId());
		  System.out.println("reportingManager.........."+employeeAndReporting);
		  //setReportingManagerId(employeeAndReporting.getProjectManager().getEmployeeId());
		   
		  employeeProjects = employeeProjectDAO.getAllEmployeeProjects(wamUser.getEmployee().getEmployeeId());
		  for(EmployeeProject employeeProject :employeeProjects)
		  {
			  projectsMap.put(employeeProject.getProject().getProjectName(), employeeProject.getProject().getProjectId());
		  }
		
		///Domestic project Assignment List
		setRenderProjectsAssignments(false);
		projectAssignment.setProject(new Project());
		System.out.println("IN IF");
		projectAssignmentsList = projectAssignmentDAO.getProjectAssignmentsByEmployeeIdProjectType(wamUser.getEmployee().getEmployeeId(),CommonLookup.PROJECT_ASSIGNMENT_TYPE_DOMESTIC);
		System.out.println("constructor end..................."+projectAssignmentsList.size());
		createDomesticProjectAssignmentForm = true;
		DomesticProjectAssignmentsList = false;
		
	}
	
	 public void buttonChangeListner(ActionEvent e){
	 selectedButton = (((MenuItem)e.getComponent()).getValue().toString());
     if(selectedButton.equals(CommonLookup.CREATE_PA_BUTTON))
     {
		createDomesticProjectAssignmentForm = true;
		DomesticProjectAssignmentsList = false;
		
	 }
     else if(selectedButton.equals(CommonLookup.VIEWUPDATE_PA_BUTTON))
     {
		  DomesticProjectAssignmentsList = true;
		  createDomesticProjectAssignmentForm = false;
		 
	 }
	 }
	 
	 
	 ///Create Domestic Project Assignment 
	 public void projectChangeListener(AjaxBehaviorEvent e) {
			System.out.println("..................projectChangeListener");
			if(selectedProjectId == null || selectedProjectId == 0)
			{
			
			}
			else
			{
				selectedProject = projectDAO.getProjectByProjectID(selectedProjectId);
			}
	     }

		public void advanceAmountChangeListener(AjaxBehaviorEvent e){
			advanceAmount = projectAssignmentDetail.getAdvanceAmount();
			projectAssignmentDetail.setTotalAdvance(advanceAmount);
			System.out.println("bbbbbbbbbbbbbbb............: " + projectAssignmentDetail.getTotalAdvance());
		
		}
		public void roomRentAdvanceChangeListener(AjaxBehaviorEvent e){
			advanceAmount = projectAssignmentDetail.getAdvanceAmount();
			roomRentAdvance = projectAssignmentDetail.getRoomRentAdvance();
			projectAssignmentDetail.setTotalAdvance(advanceAmount+roomRentAdvance);
			System.out.println("bbbbbbbbbbbbbbb..............: " + projectAssignmentDetail.getTotalAdvance());
		
		}
		public String saveDomesticProjectAssignmentAction() 
		{
		validateForm();
	 		if(FORM_VALID){
	 			    emailUtil = new EmailUtil();
	 				projectAssignment.setProjectAssignmentCode(projectAssignmentCode);
	 	 			projectAssignment.setCreateDate(new Date());
	 	 			projectAssignmentDetail.setCreateDate(new Date());
	 	 			projectAssignment.setEmployee(wamUser.getEmployee());
	 	 			projectAssignment.setProject(selectedProject);
	 	 			projectAssignment.setContactNumber(wamUser.getEmployee().getTelephone());
	 	 			projectAssignment.setApprovedBy(CommonLookup.PROJECTASSIGNMENT_DOMESTIC_INTERNATIONAL_APPROVER);
	 	 			projectAssignment.setProjectManager(employeeAndReporting.getProjectManager());
	 	 			projectAssignment.setRecommendedBy(selectedProject.getOwner().getFirstName() +" "+ selectedProject.getOwner().getLastName());
	 	 			projectAssignment.setProjectType(CommonLookup.PROJECT_ASSIGNMENT_TYPE_DOMESTIC);
	 	 			projectAssignment.setCreatedBy(wamUser.getEmployee().getFirstName() +" "+ wamUser.getEmployee().getLastName());
	 	 			projectAssignmentDetail.setCreatedBy(wamUser.getEmployee().getFirstName() +" "+ wamUser.getEmployee().getLastName());
	 	 			projectAssignment.setApprovalStatus(CommonLookup.PROJECT_ASSIGNMENT_INPROCESS_STATUS);
	 	 			projectAssignmentDetail.setApprovalStatus(CommonLookup.PROJECT_ASSIGNMENT_INPROCESS_STATUS);
	 	 			projectAssignment.setRecommendationStatus(CommonLookup.PROJECT_ASSIGNMENT_INPROCESS_STATUS);
	 	 			projectAssignmentDetail.setRecommendationStatus(CommonLookup.PROJECT_ASSIGNMENT_INPROCESS_STATUS);
	 	 			projectAssignment.setStatus(CommonLookup.STATUS_ACTIVE);
	 	 			projectAssignmentDetail.setStatus(CommonLookup.STATUS_ACTIVE);
	 	 			projectAssignment.getProjectAssignmentDetails().add(projectAssignmentDetail);
	 	 		
	 	 			if(projectAssignmentDAO.createProjectAssignment(projectAssignment) != null){
	 	 				System.out.println("AT CALLER METHOD: " + sendMessage());
	 	 				FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, projectAssignment.getProjectAssignmentId() + " ProjectAssignment created successfully.", ""));
	 	 				projectAssignment = new ProjectAssignment();
	 	 			}else{
	 	 				FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Failed to create ProjectAssignment.", ""));
	 	 			}
	 	 		
	 			}
	 		else
	 		{
	 			
	 		}
	 	System.out.println("In save ProjectAssignment");
		return null;
		}
	 
	///Domestic Project Assignment List
	 public String viewProjectAssignmentInEditMode()
		{
			
		System.out.println("viewProjectAssignmentInEditMode");
		System.out.println("projectAssignment................vvvvvvvv......." + (projectAssignment == null ? null : projectAssignment.getProjectAssignmentId()));
		System.out.println(projectAssignment.getProject());
		
		List<ProjectAssignmentDetail> temp =  new ArrayList<ProjectAssignmentDetail>();
		temp.addAll(projectAssignment.getProjectAssignmentDetails());
		projectAssignmentDetail = temp.get(0);
				
		employeeProjects = employeeProjectDAO.getAllEmployeeProjects(wamUser.getEmployee().getEmployeeId());
		  for(EmployeeProject employeeProject :employeeProjects)
		  {
			  projectsMap.put(employeeProject.getProject().getProjectName(), employeeProject.getProject().getProjectId());
		  }
			
		SHOW_EDIT_DIALOG = true;
		if(projectAssignmentDetail.getApprovalStatus().equals("APPROVED") || projectAssignmentDetail.getRecommendationStatus().equals("RECOMMENDED"))
		{
		System.out.println("1111111111111111");
		setRenderUpdate(false);
		setRenderDisableUpdate(true);
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, projectAssignment.getProjectAssignmentId() + " ProjectAssignment is sent for Approval!", ""));
		}
		else
		{
		System.out.println("22222222222222");
		setRenderUpdate(true);		
		setRenderDisableUpdate(false);
		//FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, projectAssignment.getProjectAssignmentId() + " ProjectAssignment is Inprocess!", ""));
		}
		return null;
		}
		
		public void projectChangeListenerUpdate(AjaxBehaviorEvent e) {
		selectedProjectId = Long.parseLong(((SelectOneMenu)e.getComponent()).getValue().toString());
		System.out.println(selectedProjectId);
		projectAssignment.setProject(projectDAO.getProjectByProjectID(selectedProjectId));
	     }
		
		public void advanceAmountChangeListenerUpdate(AjaxBehaviorEvent e){
		advanceAmount = projectAssignmentDetail.getAdvanceAmount();
		projectAssignmentDetail.setTotalAdvance(advanceAmount);
		System.out.println("getTotalAdvance.`..........11111111: " + projectAssignmentDetail.getTotalAdvance());

		} 
		
		public void roomRentAdvanceChangeListenerUpdate(AjaxBehaviorEvent e){
		advanceAmount = projectAssignmentDetail.getAdvanceAmount();
		roomRentAdvance = projectAssignmentDetail.getRoomRentAdvance();
		projectAssignmentDetail.setTotalAdvance(advanceAmount+roomRentAdvance);
		System.out.println("getTotalAdvance............2222222222: " + projectAssignmentDetail.getTotalAdvance());

		}
		
		//UPDATE ACTION
		public String updateDomesticProjectAssignment() 
		{
		System.out.println("In  updateDomesticProjectAssignment");

		System.out.println("2222222222222222222");
		validateFormUpdate();
		if(FORM_VALID){
			
		projectAssignment.setApprovalStatus(CommonLookup.PROJECT_ASSIGNMENT_INPROCESS_STATUS);
		projectAssignmentDetail.setApprovalStatus(CommonLookup.PROJECT_ASSIGNMENT_INPROCESS_STATUS);
		projectAssignment.setRecommendationStatus(CommonLookup.PROJECT_ASSIGNMENT_INPROCESS_STATUS);
		projectAssignmentDetail.setRecommendationStatus(CommonLookup.PROJECT_ASSIGNMENT_INPROCESS_STATUS);
	    projectAssignment.setStatus(CommonLookup.STATUS_ACTIVE);
		projectAssignmentDetail.setStatus(CommonLookup.STATUS_ACTIVE);
		projectAssignment.setModifiedBy(wamUser.getEmployee().getFirstName() +" "+ wamUser.getEmployee().getLastName());
		projectAssignmentDetail.setModifiedBy(wamUser.getEmployee().getFirstName() +" "+ wamUser.getEmployee().getLastName());
		projectAssignment.setDateModified(new Date());
		projectAssignmentDetail.setDateModified(new Date());
		
		if(projectAssignmentDAO.updateProjectAssignment(projectAssignment) != null ){
		System.out.println("In update success....");
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, projectAssignment.getProjectAssignmentId() + " ProjectAssignment updated successfully.", ""));
		System.out.println("In update success....after");
		projectAssignment = new ProjectAssignment();
		projectAssignment.setProject(new Project());
		}else
		{
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Failed to update ProjectAssignment.", ""));
		}
		RequestContext.getCurrentInstance().execute("EditProjectAssignmentDialog.hide();");
		}
		
		else
		{
			RequestContext.getCurrentInstance().execute("EditProjectAssignmentDialog.show();");			
		}
		return null;
		}

		//CLOSE ACTION
		public void dialogClose(){	
			System.out.println("dialogClose .................");
			RequestContext.getCurrentInstance().execute("EditProjectAssignmentDialog.hide()");		
			}
		private void validateForm(){
			System.out.println("validateForm.....................");
			FORM_VALID = true;
			System.out.println("projectAssignment.getEmergencycontactNumber()....................."+projectAssignment.getEmergencycontactNumber());
			if(ValidationUtil.isEmpty(projectAssignment.getEmergencycontactNumber(), "Emergency Contact Number ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			
			if(ValidationUtil.isEmpty(selectedProjectId.toString() , "Project", "", FacesContext.getCurrentInstance()) != null || ValidationUtil.isNonZero(selectedProjectId, "Project ", "", FacesContext.getCurrentInstance()) != null)
			{
				System.out.println("selectedProjectId.toString()...111111111........"+selectedProjectId.toString());
			FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(String.valueOf(projectAssignmentDetail.getDailyAllowance()), "Daily Allowance(INR) ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(String.valueOf(projectAssignmentDetail.getAdvanceAmount()), "Advance Amount(INR) ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(projectAssignmentDetail.getAdvanceByDate() != null ? projectAssignmentDetail.getAdvanceByDate().toString() :null , "Advance Amount By Date ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(projectAssignmentDetail.getPaymentCycleDate() != null ? projectAssignmentDetail.getPaymentCycleDate().toString() :null , "Payment Cycle [Date of every month] ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(String.valueOf(projectAssignmentDetail.getAdditionals()), "Additionals ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(String.valueOf(projectAssignmentDetail.getRoomRentAdvance()), "Room Rent Advance ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(String.valueOf(projectAssignmentDetail.getRoomRentPerMonth()), "Room Rent Per Month ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(String.valueOf(projectAssignmentDetail.getTotalAdvance()), "Total Amount ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			
			System.out.println("Finally FORM_VALID is :::::"+FORM_VALID);
		}

		private void validateFormUpdate(){
			System.out.println("validateForm.....................");
			FORM_VALID = true;
			if(ValidationUtil.isEmpty(projectAssignment.getEmergencycontactNumber(), "Emergency Contact Number ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			
			
			if(ValidationUtil.isEmpty(String.valueOf(projectAssignmentDetail.getDailyAllowance()), "Daily Allowance(INR) ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(String.valueOf(projectAssignmentDetail.getAdvanceAmount()), "Advance Amount(INR) ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(projectAssignmentDetail.getAdvanceByDate() != null ? projectAssignmentDetail.getAdvanceByDate().toString() :null , "Advance Amount By Date ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(projectAssignmentDetail.getPaymentCycleDate() != null ? projectAssignmentDetail.getPaymentCycleDate().toString() :null , "Payment Cycle [Date of every month] ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(String.valueOf(projectAssignmentDetail.getAdditionals()), "Additionals ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(String.valueOf(projectAssignmentDetail.getRoomRentAdvance()), "Room Rent Advance ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(String.valueOf(projectAssignmentDetail.getRoomRentPerMonth()), "Room Rent Per Month ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			if(ValidationUtil.isEmpty(String.valueOf(projectAssignmentDetail.getTotalAdvance()), "Total Amount ", null, FacesContext.getCurrentInstance()) != null){
				FORM_VALID = false;
			}
			
			System.out.println("Finally FORM_VALID is :::::"+FORM_VALID);
		}

		//Email Functionality
		public String sendMessage(){
			Map<String, String> hostsMap = WAMHostManager.getWAMHosts(context);
			String domainName = context.getInitParameter("domainName");
			
			if(hostsMap.get(CommonLookup.DEV_EMAIL) == null){
				String[] to = {selectedProject.getOwner().getEmail()};
				emailUtil.setRecieverAddresses(to);
			}else{
				String[] to = {hostsMap.get(CommonLookup.DEV_EMAIL)};
				emailUtil.setRecieverAddresses(to);
			}
			
			String requestURL = "ac/project/approvedomesticprojectassignment.html";
			String privateLink = "http://" + hostsMap.get(CommonLookup.PRIVATEHOST) + "/" + domainName + "/" + requestURL+"?projectAssignmentId="+projectAssignment.getProjectAssignmentId();
			String publicLink = "http://" + hostsMap.get(CommonLookup.PUBLICHOST) + "/"	+ domainName + "/" + requestURL+"?projectAssignmentId="+projectAssignment.getProjectAssignmentId();
			String messageString = "Dear " + selectedProject.getOwner().getFirstName() + " " + selectedProject.getOwner().getLastName() + ",<br /><br />" + 
						"<a style='color:#FF9933;font-weight: bold;' href=\""+
						privateLink + "\">" + "Please click here to approve/reject domestic project assignment"+" "+projectAssignment.getProjectAssignmentCode() + "</a /><br /><br />"+
						"(Employees who are in Hyderabad office)"+"<br /><br />"+
						"<a style='color:#FF9933;font-weight: bold;' href=\""+
						publicLink + "\">" + "Please click here to approve/reject domestic project assignment"+" "+projectAssignment.getProjectAssignmentCode() + "</a /><br />"+
						"(Out side of Hyderabad office)"+"<br /><br />"+

					    "Thanks & Regards, <br />"
					    + CommonLookup.WAM_DEVTEAM_SIGNATURE;
			 
			emailUtil.setMessage(messageString);
			emailUtil.setSenderEmail("podquick@erpanderp.com", "WAM - Dev Team");
			emailUtil.setSubject("Domestic project assignment request-"+projectAssignment.getProjectAssignmentCode());

			SwingWorker worker = new SwingWorker<String, Object>() {
				@Override
				protected String doInBackground() throws Exception {
					EMAIL_MESSAGE = emailUtil.processAndSendEmail();
					return null;
				}

				@Override
				protected void done() {
						System.out.println("DONE " + EMAIL_MESSAGE);		
				}
			};
			worker.execute();
			System.out.println( "BEFORE RETURNING: " + EMAIL_MESSAGE);
			return EMAIL_MESSAGE;
		}
		
	//GETTERS AND SETTERS
	
	public boolean isCreateDomesticProjectAssignmentForm() {
		return createDomesticProjectAssignmentForm;
	}

	public void setCreateDomesticProjectAssignmentForm(
			boolean createDomesticProjectAssignmentForm) {
		this.createDomesticProjectAssignmentForm = createDomesticProjectAssignmentForm;
	}
	public HttpSession getSession() {
		return session;
	}

	public void setSession(HttpSession session) {
		this.session = session;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public boolean isDomesticProjectAssignmentsList() {
		return DomesticProjectAssignmentsList;
	}

	public void setDomesticProjectAssignmentsList(
			boolean domesticProjectAssignmentsList) {
		DomesticProjectAssignmentsList = domesticProjectAssignmentsList;
	}

	

	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	public String getSelectedButton() {
		return selectedButton;
	}

	public void setSelectedButton(String selectedButton) {
		this.selectedButton = selectedButton;
	}

	public ProjectDAO getProjectDAO() {
		return projectDAO;
	}

	public void setProjectDAO(ProjectDAO projectDAO) {
		this.projectDAO = projectDAO;
	}

	public ProjectAssignmentDAO getProjectAssignmentDAO() {
		return projectAssignmentDAO;
	}

	public void setProjectAssignmentDAO(ProjectAssignmentDAO projectAssignmentDAO) {
		this.projectAssignmentDAO = projectAssignmentDAO;
	}

	public ProjectAssignmentDetailDAO getProjectAssignmentDetailDAO() {
		return projectAssignmentDetailDAO;
	}

	public void setProjectAssignmentDetailDAO(
			ProjectAssignmentDetailDAO projectAssignmentDetailDAO) {
		this.projectAssignmentDetailDAO = projectAssignmentDetailDAO;
	}

	public ProjectAssignment getProjectAssignment() {
		return projectAssignment;
	}

	public void setProjectAssignment(ProjectAssignment projectAssignment) {
		this.projectAssignment = projectAssignment;
	}

	public ProjectAssignmentDetail getProjectAssignmentDetail() {
		return projectAssignmentDetail;
	}

	public void setProjectAssignmentDetail(
			ProjectAssignmentDetail projectAssignmentDetail) {
		this.projectAssignmentDetail = projectAssignmentDetail;
	}

	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	public Project getSelectedProject() {
		return selectedProject;
	}

	public void setSelectedProject(Project selectedProject) {
		this.selectedProject = selectedProject;
	}

	public WAMUser getWamUser() {
		return wamUser;
	}

	public void setWamUser(WAMUser wamUser) {
		this.wamUser = wamUser;
	}

	public Employee getReportingManager() {
		return reportingManager;
	}

	public void setReportingManager(Employee reportingManager) {
		this.reportingManager = reportingManager;
	}

	public boolean isSHOW_EDIT_DIALOG() {
		return SHOW_EDIT_DIALOG;
	}

	public void setSHOW_EDIT_DIALOG(boolean sHOW_EDIT_DIALOG) {
		SHOW_EDIT_DIALOG = sHOW_EDIT_DIALOG;
	}

	public boolean isFORM_VALID() {
		return FORM_VALID;
	}

	public void setFORM_VALID(boolean fORM_VALID) {
		FORM_VALID = fORM_VALID;
	}

	public boolean isRenderApproveReject() {
		return renderApproveReject;
	}

	public void setRenderApproveReject(boolean renderApproveReject) {
		this.renderApproveReject = renderApproveReject;
	}

	public boolean isRenderUpdate() {
		return renderUpdate;
	}

	public void setRenderUpdate(boolean renderUpdate) {
		this.renderUpdate = renderUpdate;
	}

	public boolean isRenderDisableUpdate() {
		return renderDisableUpdate;
	}

	public void setRenderDisableUpdate(boolean renderDisableUpdate) {
		this.renderDisableUpdate = renderDisableUpdate;
	}

	public boolean isRenderClose() {
		return renderClose;
	}

	public void setRenderClose(boolean renderClose) {
		this.renderClose = renderClose;
	}

	public boolean isRenderProjectsAssignmentsList() {
		return renderProjectsAssignmentsList;
	}

	public void setRenderProjectsAssignmentsList(
			boolean renderProjectsAssignmentsList) {
		this.renderProjectsAssignmentsList = renderProjectsAssignmentsList;
	}

	public boolean isRenderProjectsAssignments() {
		return renderProjectsAssignments;
	}

	public void setRenderProjectsAssignments(boolean renderProjectsAssignments) {
		this.renderProjectsAssignments = renderProjectsAssignments;
	}

	public List<ProjectAssignment> getProjectAssignmentsList() {
		return projectAssignmentsList;
	}

	public void setProjectAssignmentsList(
			List<ProjectAssignment> projectAssignmentsList) {
		this.projectAssignmentsList = projectAssignmentsList;
	}

	public List<ProjectAssignmentDetail> getProjectAssignmentDetailList() {
		return projectAssignmentDetailList;
	}

	public void setProjectAssignmentDetailList(
			List<ProjectAssignmentDetail> projectAssignmentDetailList) {
		this.projectAssignmentDetailList = projectAssignmentDetailList;
	}

	

	public Map<String, Long> getProjectsMap() {
		return projectsMap;
	}

	public void setProjectsMap(Map<String, Long> projectsMap) {
		this.projectsMap = projectsMap;
	}

	public Long getProjectAssignmentId() {
		return projectAssignmentId;
	}

	public void setProjectAssignmentId(Long projectAssignmentId) {
		this.projectAssignmentId = projectAssignmentId;
	}

	public Long getSelectedProjectId() {
		return selectedProjectId;
	}

	public void setSelectedProjectId(Long selectedProjectId) {
		this.selectedProjectId = selectedProjectId;
	}

	public String getProjectAssignmentCode() {
		return projectAssignmentCode;
	}

	public void setProjectAssignmentCode(String projectAssignmentCode) {
		this.projectAssignmentCode = projectAssignmentCode;
	}

	public String getEmployeeId() {
		return employeeId;
	}

	public void setEmployeeId(String employeeId) {
		this.employeeId = employeeId;
	}

	public String getContactNumber() {
		return contactNumber;
	}

	public void setContactNumber(String contactNumber) {
		this.contactNumber = contactNumber;
	}

	public String getApprovedBy() {
		return approvedBy;
	}

	public void setApprovedBy(String approvedBy) {
		this.approvedBy = approvedBy;
	}

	public Float getAdvanceAmount() {
		return advanceAmount;
	}

	public void setAdvanceAmount(Float advanceAmount) {
		this.advanceAmount = advanceAmount;
	}

	public Float getRoomRentAdvance() {
		return roomRentAdvance;
	}

	public void setRoomRentAdvance(Float roomRentAdvance) {
		this.roomRentAdvance = roomRentAdvance;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public String getAdditionals() {
		return additionals;
	}

	public void setAdditionals(String additionals) {
		this.additionals = additionals;
	}
	public RRFDAO getRrfDAO() {
		return rrfDAO;
	}

	public void setRrfDAO(RRFDAO rrfDAO) {
		this.rrfDAO = rrfDAO;
	}

	public EmployeeAndReportingDAO getEmployeeAndReportingDAO() {
		return employeeAndReportingDAO;
	}

	public void setEmployeeAndReportingDAO(
			EmployeeAndReportingDAO employeeAndReportingDAO) {
		this.employeeAndReportingDAO = employeeAndReportingDAO;
	}

	public EmployeeAndReporting getEmployeeAndReporting() {
		return employeeAndReporting;
	}

	public void setEmployeeAndReporting(EmployeeAndReporting employeeAndReporting) {
		this.employeeAndReporting = employeeAndReporting;
	}

	public String getEMAIL_MESSAGE() {
		return EMAIL_MESSAGE;
	}

	public void setEMAIL_MESSAGE(String eMAIL_MESSAGE) {
		EMAIL_MESSAGE = eMAIL_MESSAGE;
	}

	public Long getReportingManagerId() {
		return reportingManagerId;
	}

	public void setReportingManagerId(Long reportingManagerId) {
		this.reportingManagerId = reportingManagerId;
	}

	public EmailUtil getEmailUtil() {
		return emailUtil;
	}

	public void setEmailUtil(EmailUtil emailUtil) {
		this.emailUtil = emailUtil;
	}
	public ServletContext getContext() {
		return context;
	}

	public void setContext(ServletContext context) {
		this.context = context;
	}

	public EmployeeProject getEmployeeProject() {
		return employeeProject;
	}

	public void setEmployeeProject(EmployeeProject employeeProject) {
		this.employeeProject = employeeProject;
	}
	public EmployeeProjectDAO getEmployeeProjectDAO() {
		return employeeProjectDAO;
	}

	public void setEmployeeProjectDAO(EmployeeProjectDAO employeeProjectDAO) {
		this.employeeProjectDAO = employeeProjectDAO;
	}

	public List<EmployeeProject> getEmployeeProjects() {
		return employeeProjects;
	}

	public void setEmployeeProjects(List<EmployeeProject> employeeProjects) {
		this.employeeProjects = employeeProjects;
	}

}


